import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public final class at {

    public static final at a = new at(0);
    public int b;
    public g c;
    public u d;
    public int e;
    public int f;
    public int g;

    public at(int i) {
        b = i;
    }

    public final void a(Graphics g1, int i, int j) {

        switch (b) {
            case 0:
                return;
            case 1:
                g1.setColor(e);
                g1.fillRect(0, 0, i, j);
                return;
            case 2:
                for (int l = 0; l < i; l++) {
                    g1.setColor(a(e, f, l, i));
                    g1.drawLine(l, 0, l, j - 1);
                }

                return;
            case 3:
                for (int i1 = 0; i1 < j; i1++) {
                    g1.setColor(a(e, f, i1, j));
                    g1.drawLine(0, i1, i - 1, i1);
                }

                return;
            case 4:
                int k;
                boolean flag = ((k = g) & 0x40) != 0;
                boolean flag1 = (k & 0x80) != 0;
                Image image1;
                int l1 = (image1 = d.a).getWidth();
                int j2 = image1.getHeight();
                if ((k & 0x100) == 0 && (!flag1 || !flag)) {
                    g1.setColor(e);
                    g1.fillRect(0, 0, i, j);
                }
                int l2 = 0;
                switch (k & 0x32) {
                    case 2: // '\002'
                        l2 = (j - j2) / 2;
                        break;

                    case 32: // ' '
                        l2 = j - j2;
                        break;
                }
                if (flag1 && (l2 -= (l2 / j2) * j2) > 0)
                    l2 -= j2;
                int j3 = 0;
                switch (k & 0xd) {
                    case 1: // '\001'
                        j3 = (i - l1) / 2;
                        break;

                    case 8: // '\b'
                        j3 = i - l1;
                        break;
                }
                if (flag && (j3 -= (j3 / l1) * l1) > 0)
                    j3 -= l1;
                byte byte0 = 0;
                if ((k & 0x200) != 0)
                    byte0 = 3;
                while (l2 < j) {
                    int l3 = Math.min(j2, j - l2);
                    int i4 = j3;
                    int j4 = 0;
                    if (l2 < 0) {
                        l3 += l2;
                        j4 = -l2;
                        l2 = 0;
                    }
                    do {
                        if (i4 >= i)
                            break;
                        int k4 = Math.min(l1, i - i4);
                        int l4 = 0;
                        if (i4 < 0) {
                            k4 += i4;
                            l4 = -i4;
                            i4 = 0;
                        }
                        g1.drawRegion(image1, l4, j4, k4, l3, byte0, i4, l2, 20);
                        if (!flag)
                            break;
                        i4 += k4;
                    } while (true);
                    l2 += l3;
                    if (!flag1)
                        return;
                }
                return;
            case 5:
            case 6:
                break;
        }

        switch (b) {
            case 0:
                return;
            case 1:
                g1.setColor(e);
                g1.fillRect(0, 0, i, j);
                return;
            case 2:
                for (int l = 0; l < i; l++) {
                    g1.setColor(a(e, f, l, i));
                    g1.drawLine(l, 0, l, j - 1);
                }

                return;
            case 3:
                for (int i1 = 0; i1 < j; i1++) {
                    g1.setColor(a(e, f, i1, j));
                    g1.drawLine(0, i1, i - 1, i1);
                }

                return;
            case 4:
                int k;
                boolean flag = ((k = g) & 0x40) != 0;
                boolean flag1 = (k & 0x80) != 0;
                Image image1;
                int l1 = (image1 = d.a).getWidth();
                int j2 = image1.getHeight();
                if ((k & 0x100) == 0 && (!flag1 || !flag)) {
                    g1.setColor(e);
                    g1.fillRect(0, 0, i, j);
                }
                int l2 = 0;
                switch (k & 0x32) {
                    case 2: // '\002'
                        l2 = (j - j2) / 2;
                        break;

                    case 32: // ' '
                        l2 = j - j2;
                        break;
                }
                if (flag1 && (l2 -= (l2 / j2) * j2) > 0)
                    l2 -= j2;
                int j3 = 0;
                switch (k & 0xd) {
                    case 1: // '\001'
                        j3 = (i - l1) / 2;
                        break;

                    case 8: // '\b'
                        j3 = i - l1;
                        break;
                }
                if (flag && (j3 -= (j3 / l1) * l1) > 0)
                    j3 -= l1;
                byte byte0 = 0;
                if ((k & 0x200) != 0)
                    byte0 = 3;
                while (l2 < j) {
                    int l3 = Math.min(j2, j - l2);
                    int i4 = j3;
                    int j4 = 0;
                    if (l2 < 0) {
                        l3 += l2;
                        j4 = -l2;
                        l2 = 0;
                    }
                    do {
                        if (i4 >= i)
                            break;
                        int k4 = Math.min(l1, i - i4);
                        int l4 = 0;
                        if (i4 < 0) {
                            k4 += i4;
                            l4 = -i4;
                            i4 = 0;
                        }
                        g1.drawRegion(image1, l4, j4, k4, l3, byte0, i4, l2, 20);
                        if (!flag)
                            break;
                        i4 += k4;
                    } while (true);
                    l2 += l3;
                    if (!flag1)
                        return;
                }
                return;
            case 5:
            case 6:
                g g2 = c;
                if (ch.a(g1, d, g2, i, j)) {
                    Image image;
                    int j1;
                    int k1;
                    i -= g2.b + g2.c;
                    j -= g2.d + g2.e;
                    if (b == 5) {
                        if (f == 0)
                            a();
                        if (f == 2) {
                            g1.setColor(e);
                            g1.fillRect(g2.b, g2.d, i, j);
                            return;
                        }
                        if (f == 1)
                            return;
                    }
                    j1 = (image = d.a).getWidth() - g2.b - g2.c;
                    k1 = image.getHeight() - g2.d - g2.e;
                    for (int i2 = 0; i2 < j;) {
                        int k2 = Math.min(k1, j - i2);
                        for (int i3 = 0; i3 < k2;) {
                            int k3;
                            k3 = Math.min(j1, i - i3);
                            g1.drawRegion(image, g2.b, g2.d, k3, k2, 0, g2.b + i3, g2.d + i2, 20);
                            i3 += k3;
                        }
                        i2 += k2;
                    }
                }
                break;
        }
    }

    private void a() {
        if (ce.a(25)) {
            f = 3;
        } else {
            int ai[] = new int[1];
            d.a.getRGB(ai, 0, 1, c.b, c.d, 1, 1);
            e = ai[0] & 0xffffff;
            f = 2;
        }
    }

    public static int a(int i, int j, int k, int l) {
        int i1 = i >> 16 & 0xff;
        int j1 = i >> 8 & 0xff;
        int k1 = i & 0xff;
        return i1 + (((j >> 16 & 0xff) - i1) * k) / l << 16 | j1 + (((j >> 8 & 0xff) - j1) * k) / l << 8 | k1 + (((j & 0xff) - k1) * k) / l;
    }
}